#! /usr/bin/env python3
import os
import sys
sys.path.append(os.path.dirname(os.getcwd()))
from webPathUtil import fromPathToHtml


def get_sel_part(add_sel=""):
    result = ""
    with open("html/float.web", "r", encoding="UTF-8") as f:
        constent = f.read()
        result = constent.format(seli=add_sel)
    return result


def get_main_html(body, sel):
    head = "Content-type:text/html\n\n"
    with open("html/main.web", "r", encoding="UTF-8") as f:
        constent = f.read()
        constent = constent.format(main=body, sel_part=get_sel_part(sel))
        return head + constent


def main(note_path, except_list):
    sel_add = ""
    for name in os.listdir(note_path):
        if "." not in name:
            cont = "     <li><a href=\"#%s\" target=\"_self\">%s</a></li></br>\n" % (name, name)
            sel_add += cont
    print(get_main_html(fromPathToHtml.file_tree_with_html("markdownWeb.py", note_path, except_list), sel_add))
